package com.AAL.Action;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.struts2.interceptor.SessionAware;

import com.AAL.DAO.TypeOfAutoDAO;
import com.AAL.DAO.WheelDetailDAO;
import com.AAL.Model.TypeOfAuto;
import com.AAL.Model.WheelDetail;
import com.opensymphony.xwork2.ActionSupport;

@SuppressWarnings("serial")
public class IndexAction extends ActionSupport implements SessionAware {

	private TypeOfAutoDAO lnkTypeOfAutoDAO;
	private WheelDetailDAO lnkWheelDetailDAO;

	private List<TypeOfAuto> lstTypeOfAutos;
	private List<WheelDetail> lstWheelDetails;

	private Map<String, Object> session;
	
	public IndexAction() {
		this.lnkTypeOfAutoDAO = new TypeOfAutoDAO();
		this.lnkWheelDetailDAO = new WheelDetailDAO();
	}

	public String execute() {
		try {
			/*List<TypeOfAuto> typeOfAutoTemp = lnkTypeOfAutoDAO.getAllTypeOfAutos();
			this.lstTypeOfAutos = new ArrayList<TypeOfAuto>();			
			for (TypeOfAuto item : typeOfAutoTemp) {
				TypeOfAuto a = new TypeOfAuto();
				a.setTypeOfAutoID(item.getTypeOfAutoID());
				a.setTypeOfAutoName(item.getTypeOfAutoName());
				this.lstTypeOfAutos.add(a);
			}*/
			this.lstTypeOfAutos = lnkTypeOfAutoDAO.getAllTypeOfAutos();
			session.put("lstTypeOfAutosForIndex", this.lstTypeOfAutos);
			/*List<WheelDetail> lstWheelDetailTemp = lnkWheelDetailDAO.getRandomLstWheelDetailForIndex();
			this.lstWheelDetails = new ArrayList<WheelDetail>();
			for (WheelDetail item : lstWheelDetailTemp) {
				WheelDetail a = new WheelDetail();
				a.setWheelDetailID(item.getWheelDetailID());
				this.lstWheelDetails.add(a);
			}*/
			this.lstWheelDetails = lnkWheelDetailDAO.getRandomLstWheelDetailForIndex();			
			session.put("lstWheelDetailForIndex", this.lstWheelDetails);
		} catch (Exception e) {
			return ERROR;
		}
		return SUCCESS;
	}

	@Override
	public void setSession(Map<String, Object> arg0) {
		this.session=arg0;
	}

	public Map<String, Object> getSession() {
		return session;
	}

	public List<TypeOfAuto> getLstTypeOfAutos() {
		return lstTypeOfAutos;
	}

	public void setLstTypeOfAutos(List<TypeOfAuto> lstTypeOfAutos) {
		this.lstTypeOfAutos = lstTypeOfAutos;
	}

	public List<WheelDetail> getLstWheelDetails() {
		return lstWheelDetails;
	}

	public void setLstWheelDetails(List<WheelDetail> lstWheelDetails) {
		this.lstWheelDetails = lstWheelDetails;
	}

}
